﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using OLMS.DAL;

namespace OLMS.BLL
{
    public class GenreBLL
    {
        //获取全部音乐类型
        public static List<Genres> GetGenresList()
        {
            using (OLMSDBEntities db = new OLMSDBEntities())
            {
                return db.Genres.ToList();
            }
        }
        //根据编号获取音乐类型信息
        public static Genres GetGenresById(int genresId)
        {
            using (OLMSDBEntities db = new OLMSDBEntities())
            {
                return db.Genres.SingleOrDefault(g => g.GenreId == genresId);
            }
        }

        //添加和编辑音乐类型
        public static bool AddOrEditGenre(Genres genres)
        {
            using (OLMSDBEntities db = new OLMSDBEntities())
            {
                if (genres.GenreId == 0)
                {
                    db.Genres.Add(genres);
                }
                else
                {
                    db.Genres.Attach(genres);
                }
                return db.SaveChanges() != -1 ? true : false;
            }
        }
        //删除音乐类型
        public static bool RemoveGenre(int genreId)
        {
            using (OLMSDBEntities db = new OLMSDBEntities())
            {
                Genres genres = db.Genres.SingleOrDefault(a => a.GenreId == genreId);
                if (genres != null)
                {
                    db.Genres.Remove(genres);
                    return db.SaveChanges() != -1 ? true : false;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}